# import sys
# import os
# sys.path.append(os.path.dirname(os.path.realpath(__file__)))

from protos import helloworld_pb2, helloworld_pb2_grpc
import grpc
from concurrent import futures

class Greeter(helloworld_pb2_grpc.GreeterServicer):

    def SayHello(self, request, context):
        return helloworld_pb2.HelloReply(message=f"您好， {request.name}")
    
if __name__ == "__main__":
    # 1.实例化server 使用线程池去启动
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    # 2.注册逻辑到server
    helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
    # 3.启动server
    server.add_insecure_port("localhost:8084")
    print("localhost:8084")
    server.start()
    server.wait_for_termination()